﻿using System;

namespace MathService.Interpolation
{
    public class Linear
    {
        public static double GetValue(double x, double x0, double y0, double x1, double y1)
        {
            return (y1 - y0) / (x1 - x0) * (x - x0) + y0;
        }

    	public double X0 { get; set; }
    	public double Y0 { get; set; }
    	public double X1 { get; set; }
    	public double Y1 { get; set; }

    	public Linear(){}

        public Linear(double x0, double y0, double x1, double y1)
        {
            X0 = x0;
            X1 = x1;
            Y0 = y0;
            Y1 = y1;
        }

        public double GetValue(double x)
        {
            return GetValue(x, X0, Y0, X1, Y1);
        }

        public static implicit operator Func<double, double>(Linear Interpolator)
        {
            return Interpolator.GetValue;
        }
    }
}
